<?php
namespace backend\controllers;

use Yii;
use yii\web\Controller;
use common\collection\Common;
use common\collection\BackendCommon;
use common\helpers\PublicFun;
use backend\config\routeParams;


/**
 * Employee controller
 */
class EmployeeController extends Controller
{

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }

    public  function beforeAction($action){
        if(BackendCommon::init()){
            if(BackendCommon::rbac()){
                return true;
            }else{
                Yii::$app->response->redirect( ['site/error']);
            }
        }else{
            Yii::$app->response->redirect( ['login/index']);
        }
    }
    //首页
    public function actionIndex()
    {
        return $this->render('index');
    }
    //员工等级列表
    public function actionEmployeelevel()
    {
        return $this->render('employeelevel');
    }

    //获取企业员工列表
    public function actionGetEnterpriseEmployeeList()
    {
        $datapost = Yii::$app->request->post();
        $datapost = Common::ArrayFilter($datapost);
        $datapost['MytipId'] =  Common::GetMytipId();
        $url = routeParams::HttpUrl('PCEnterpriseEmployeeGetList');
        $result = PublicFun::PostPackage($datapost, $url);
        $result = json_decode($result['Body'],true);
        $ret = [
            'PageNo' => $datapost['PageNo'],
            'PageSize' => $datapost["PageSize"],
            'total' => $result["TotalCounts"],
            'data' => $result['Models']
        ];
        die(json_encode($ret));
    }

    //获取企业员工等级列表
    public function actionGetEnterpriseEmployeeLevelList()
    {
        $datapost = Yii::$app->request->post();
        $datapost = Common::ArrayFilter($datapost);
        $datapost['MytipId'] =  Common::GetMytipId();
        $url = routeParams::HttpUrl('PCEnterpriseEmployeeLevelGetList');
        $result = PublicFun::PostPackage($datapost, $url);
        $result = json_decode($result['Body'],true);
        $ret = [
            'PageNo' => $datapost['PageNo'],
            'PageSize' => $datapost["PageSize"],
            'total' => $result["TotalCounts"],
            'data' => $result['Models']
        ];
        die(json_encode($ret));
    }

    //保存员工信息
    public function actionEnterpriseSaveEmployee()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['MytipId'] =  Common::GetMytipId();
        $url = routeParams::HttpUrl('PCEnterpriseEmployeeSave');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //保存员工信息
    public function actionEnterpriseSaveLevel()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['MytipId'] =  Common::GetMytipId();
        $url = routeParams::HttpUrl('PCEnterpriseEmployeeLevelSave');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }
    //获取上级员工列表
    public function actionGetParentEmployeeList()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['MytipId'] =  Common::GetMytipId();
        $url = routeParams::HttpUrl('PCEnterpriseParentEmployeeGetList');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }
    //删除员工
     public function actionEnterpriseEmployeeDel()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('PCEnterpriseEmployeeDel');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //删除员工等级
    public function actionEnterpriseEmployeeLevelDel()
    {
        $JsonData = Yii::$app->request->post();

        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('PCEnterpriseEmployeeLevelDel');
//        var_dump($url);
//        var_dump($JsonData);
//        exit;
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
//        var_dump($result);
//        exit;
        die(json_encode($result));
    }




}
